# 定义文件执行的时候的编码
# -*- coding: utf-8 -*-

import os

from pythonProject.other.click import click
from pythonProject.other.contrast import screenshot_contrast


def cmd(command):
    result = os.popen(command).read()
    print(result)
    return result

# cmd('C:\\Software\\platform-tools\\adb devices')
# cmd('C:\\Software\\platform-tools\\adb shell pm list packages -3')
# adb = 'C:\\Software\\platform-tools\\adb'
# com.netease.onmyoji.wyzymnqsd_cps/com.netease.onmyoji.tag0 bnds=[663,578][938,786]
# adb shell dumpsys activity | findstr package:com.netease.onmyoji.wyzymnqsd_cps | findstr LAUNCHER
# adb shell am start -n com.netease.onmyoji.wyzymnqsd_cps/com.netease.onmyoji.tag0 bnds=[663,578][938,786]
# adb shell screencap /storage/emulated/0/Screenshots/25.png

# 定义一个函数，用于获取安卓设备的屏幕截图
def adb_screenshots():
    # cmd('adb.exe connect 127.0.0.1:16384')
    # 使用adb命令获取安卓设备的屏幕截图，并保存到指定路径
    cmd('C:\\Software\\platform-tools\\adb shell screencap -p'
        ' /storage/emulated/0/Screenshots/screen.png')
    # 使用adb命令将截图从安卓设备拉取到本地
    cmd('C:\\Software\\platform-tools\\adb pull'
        ' /storage/emulated/0/Screenshots/screen.png '
        'image/screen.png')
    # 删除安卓设备上的截图文件
    cmd('C:\\Software\\platform-tools\\adb shell rm /storage/emulated/0/Screenshots/screen.png')

    # 调用对比函数，对比截图和模板图片
    result = screenshot_contrast('image/shop.png','image/screen.png',0.7)
    x_y = click(result)
    cmd(f"C:\\Software\\platform-tools\\adb shell input tap {x_y[0]} {x_y[1]} && echo 'Success' || echo 'Failure'")
# 调用函数，获取安卓设备的屏幕截图
adb_screenshots()


# "D:\Program Files (x86)\MuMu Player 12\shell\MuMuPlayer.exe"
